package com.eimf.saf.common.commons.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.Tag;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.eimf.saf.common.filter.I18nIntercept;
import com.eimf.saf.security.util.SysUtils;
import com.opensymphony.xwork2.util.LocalizedTextUtil;

/**
 * @author eden
 * @date 2013-11-14 下午6:24:40
 * @Description: 国际化标签实现类
 */
public class I18nTagImpl extends TagSupport
{

    private static final long serialVersionUID = 1L;
    private static Log logger = LogFactory.getLog(I18nTagImpl.class);
    private String key;

    @Override
    public int doStartTag() throws JspException
    {
        String value = "";
        if (SysUtils.isEmpty(key))
        {
            value = "key is null!";
        } else
        {
            value = LocalizedTextUtil.findDefaultText(this.key, I18nIntercept.getRequest().getLocale());
        }
        try
        {
            pageContext.getOut().write(value);
        } catch (final IOException e)
        {
            I18nTagImpl.logger.error(e.getMessage(), e);
        }
        return Tag.EVAL_BODY_INCLUDE;
    }

    public String getKey()
    {
        return key;
    }

    public void setKey(final String key)
    {
        this.key = key;
    }
}
